package com.lmabbe.common.global;

import com.lmabbe.common.global.context.LmabbeSessionUser;
import com.lmabbe.common.global.context.session.RpcLmabbeSessionUserImpl;
import com.lmabbe.common.global.context.session.WebLmabbeSessionUserImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lmabbe
 * @data 2021/12/8 22:06
 */
@ComponentScan(basePackages = {"com.lmabbe", "cn.hutool.extra.spring"})
@Configuration
public class LmabbeGlobalAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnWebApplication
    @ConditionalOnClass(value = {HttpServletRequest.class, TokenStore.class})
    public LmabbeSessionUser webLmabbeSessionUserImpl() {
        return new WebLmabbeSessionUserImpl();
    }


    @Bean
    @ConditionalOnNotWebApplication
    @ConditionalOnMissingBean
    public LmabbeSessionUser RpcLmabbeSessionUserImpl() {
        return new RpcLmabbeSessionUserImpl();
    }
}
